import 'package:flutter/services.dart';

class InputFormatter extends TextInputFormatter {
  @override
  TextEditingValue formatEditUpdate(
      TextEditingValue oldValue, TextEditingValue newValue) {
    String result = newValue.text;
    if (oldValue.text == "0") {
      result = newValue.text.replaceAll("0", "");
    }

    if(newValue.text == "") {
      result = "0";
    }
    return TextEditingValue(
      //当前的文本
      text: result,
      //光标的位置
      selection: TextSelection.collapsed(
        //设置光标的位置在 文本最后
        offset: result.length,
      ),
    );
  }
}
